home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5120 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: news.dfn.de!si-nic!usenet
  2. From: Markus Becker <becker@zess.uni-siegen.de>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Best way to make a circle
  5. Date: Fri, 09 Feb 1996 11:14:06 +0100
  6. Organization: ZESS, Uni-GH-Siegen
  7. Message-ID: <311B1E6E.6809@zess.uni-siegen.de>
  8. References: <1996Feb8.043040.19301@lafn.org>
  9. NNTP-Posting-Host: becker.zess.uni-siegen.de
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
  14.  
  15. Andres Lessing wrote:
  16. > I am working on 3d Graphics quite succesfully as of now and am trying to
  17. > put together a good Graphics library that is much faster than BGI drivers.
  18. > I know that Sin and Cosine take to much time to calculate... so... which
  19. > way should I do it?
  20.  
  21. Do it Bresenham's way:
  22.  
  23. -------------- cut here -------------
  24. void DrawCircle(int xm, int ym, int r, COLOR color)
  25. {
  26.     register int x,y, d;
  27.     
  28.     d = r - 1;
  29.  
  30.     x = 0;
  31.     y = r;
  32.  
  33.     while (x<=y)
  34.     {
  35.         if (d < 0)
  36.         {
  37.             y--;
  38.             d += (y + y);
  39.         }
  40.  
  41.         DrawPixel(xm+x, ym+y, color);
  42.         DrawPixel(xm+x, ym-y, color);
  43.         DrawPixel(xm-x, ym+y, color);
  44.         DrawPixel(xm-x, ym-y, color);
  45.  
  46.         DrawPixel(xm+y, ym+x, color);
  47.         DrawPixel(xm+y, ym-x, color);
  48.         DrawPixel(xm-y, ym+x, color);
  49.         DrawPixel(xm-y, ym-x, color);
  50.  
  51.         d -= (x + x + 1);
  52.         x++;
  53.     }
  54.     
  55. } /* DrawCircle */
  56.  
  57. ---------------- cut here --------------
  58. --
  59. Markus Becker                http://www.zess.uni-siegen.de/private/becker/
  60. Zentrum fuer Sensorsysteme (ZESS)
  61. http://www.zess.uni-siegen.de/private/becker/win95
  62.